package com.infoland.afanmall.base.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.infoland.afanmall.R;
import com.infoland.afanmall.base.util.LogKit;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;


public class TestActivity extends AppCompatActivity {
    Process process;

    @SuppressLint("ResourceAsColor")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test_activity);
//        execShellCmd("input text  'helloworld!' ");
//        execShellCmd("input tap 168 252");
//        execShellCmd("input tap 200 252");
//        execShellCmd("input tap 300 252");
//        execShellCmd("input tap 400 252");
//        execShellCmd("input tap 500 252");
//        execShellCmd("input tap 600 252");
    }


    /**
     * 执行shell命令
     *
     * @param cmd
     */
    private void execShellCmd(String cmd) {
        try {
            // 获取输出流
            process = Runtime.getRuntime().exec("su");
            OutputStream outputStream = process.getOutputStream();
            DataOutputStream dataOutputStream = new DataOutputStream(
                    outputStream);
            dataOutputStream.writeBytes(cmd);
            dataOutputStream.flush();
            dataOutputStream.close();
            outputStream.close();
        } catch (Exception t) {
            LogKit.E("aaaa ---->   ", "  异常");

            LogKit.E("aaaa ---->   ", "  " + t.getMessage());
        }
    }
//    execShellCmd("getevent -p");
//    execShellCmd("sendevent /dev/input/event0 1 158 1");
//    execShellCmd("sendevent /dev/input/event0 1 158 0");
//    execShellCmd("input keyevent 3");//home
//    execShellCmd("input text  'helloworld!' ");
//    execShellCmd("input tap 168 252");
//    execShellCmd("input swipe 100 250 200 280")

}
